<!-- верхняя часть -->
<div style="border-bottom:1px solid #ccc;">
	<h1>Добавляем <?=$razdel[$rname]['add-string'];?> в раздел &laquo;<?=$razdel[$rname]['name'];?>&raquo;</h1>
<?php
if (!empty($output)) {?>
<div class="output">
	<?php echo $output;?>
</div>
<?php
}//}
?>
</div>

<!-- // верхняя часть -->
<?php
//echo("<pre>");
//print_r($_POST);
//echo("</pre>");

//echo("date='".dt2ut($_POST['edit']['newdate'])."'");


?>
<br/>
<?php

$form=new form_class;

/*
 * Define the name of the form to be used for example in Javascript
 * validation code generated by the class.
 */
	$form->NAME="add_form";
/*
 * Define the name of the form to be used for example in Javascript
 * validation code generated by the class.
 */
	$form->SCLASS="otziv-form";

/*
 * Use the GET method if you want to see the submitted values in the form
 * processing URL, or POST otherwise.
 */
	$form->METHOD="POST";

/*
 * Make the form be displayed and also processed by this script.
 */
	$form->ACTION="";
/*
 * Output all validation errors at once.
 */
	$form->ShowAllErrors=1;

/*
 * Проходим по всем полям раздела и строим форму
 */
 
    /*$form->AddInput(array(
     "NAME"=>"id",
     "ID"=>"id",
     "VALUE"=>$Cbj['ID'],
     "TYPE"=>"hidden"
   ));*/
 
 
 $i=0;
 foreach ($razdel[$rname]['fields'] as $field) {
 
    $value="";
   
   if (empty($input_ID)) $input_ID="";
   
 	//определяем типы полей ввода
 	if ($field['type']=="varchar") $type="text";
 	else if ($field['type']=="text") $type="textarea";
 	//else if ($field['fname']=="title") $value="Фактический баланс электрической энергии ";
 	else if ($field['type']=="image") $type="file";
 	else if ($field['type']=="date") {
 		
 		 $type="text";
 		 $value=($conf_timenow);
 	
 	}//if date
 	else if ($field['type']=="elrte") {
 	
 		$elrte_i=0;
 	
 		 $type="textarea";
 		 $input_ID="control-elrte".$elrte_i;
 		 //$input_ID="control-elrte";
 		 
 		 $elrte_i++;
 	
 	}//if date
 	else $type="text";
 
 //date("Y-m-d H:i:s", $Obj[$field['fname']])
 	//print_r($field);


	if ($field['type']=="category") {
	
		//echo("Ку-ку");
	
		$catarr=GetChildCategory ($rname, 0);
		
		$in_arr=array();
		
		//print_r($catarr);
		if (empty($value)) $value=0;
		$in_arr[0]="-- Выберите категорию --";
		
		foreach ($catarr as $cat) {
		
			$in_arr[$cat['ID']]=$cat['CatName'];
		
		}//foreach
		
	
		$form->AddInput(array(
			"TYPE"=>"select",
			"NAME"=>"add[".$field['fname']."]",
	     	"ID"=>$field['fname'],
			"VALUE"=>$value,
			"SIZE"=>1,
			"OPTIONS"=>$in_arr,
			"ValidateAsDifferentFromText"=>"pick",
			"ValidateAsDifferentFromTextErrorMessage"=>
				"Выберите категорию для текущего документа",
			"ValidationErrorMessage"=>"Надо указать категорию документа",
			"LABEL"=>"Категория"
		));
	
	}//if ($field['type']=="category") {
	else {
	
	   $form->AddInput(array(
	     "NAME"=>"add[".$field['fname']."]",
	     "ID"=>$field['fname'],
	     "TYPE"=>$type,
	     "VALUE"=>$value
	   )); 	
	
	}//else //if ($field['type']=="category") {	

 $i++;
 }//foreach ($razdel[$rname]['fields'] as $field) {
 
 
   $form->AddInput(array(
     "ID"=>"submit",
     "VALUE"=>"Сохранить",
     "TYPE"=>"submit",
     "CLASS"=>"submit"
   ));
   /*
   $form->AddInput(array(
     "ID"=>"cancel",
     "VALUE"=>"Отмена",
     "TYPE"=>"submit",
     "CLASS"=>"submit"
   ));
   */
   $form->StartLayoutCapture();
   ?>
   
   
   
<?php   


/*
 * Проходим по всем полям раздела и строим форму
 */
 foreach ($razdel[$rname]['fields'] as $field) {
	?>
	<div class="field">
		 <div class="fname <?=$field['type']?>">
		   <?php
		   $form->AddLabelPart(array(
		     "FOR"=>$field['fname'],
		     "LABEL"=>$field['name']
		     //"ACCESSKEY"=>"P"
		   ));
		 ?>
		</div> 
	 	<div class="fform"><?php $form->AddInputPart($field['fname']); ?></div>
	 	
	 </div>
<?php
 }//foreach ($razdel[$rname]['fields'] as $field) {

?><?php $form->AddInputPart("id"); ?>

	
	  <div class="field"><?php $form->AddInputPart("submit"); ?></div>
	  
  
  
   <?
   $form->EndLayoutCapture();

   $form->DisplayOutput();


?>